home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 118 / cd-rom 118.iso / aplic / open / openofficeorg2.cab / math.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2005-01-31  |  27.6 KB  |  616 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.    The Contents of this file are made available subject to the terms of
  4.    either of the following licenses
  5.  
  6.           - GNU Lesser General Public License Version 2.1
  7.           - Sun Industry Standards Source License Version 1.1
  8.  
  9.    Sun Microsystems Inc., October, 2000
  10.  
  11.    GNU Lesser General Public License Version 2.1
  12.    =============================================
  13.    Copyright 2000 by Sun Microsystems, Inc.
  14.    901 San Antonio Road, Palo Alto, CA 94303, USA
  15.  
  16.    This library is free software; you can redistribute it and/or
  17.    modify it under the terms of the GNU Lesser General Public
  18.    License version 2.1, as published by the Free Software Foundation.
  19.  
  20.    This library is distributed in the hope that it will be useful,
  21.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  23.    Lesser General Public License for more details.
  24.  
  25.    You should have received a copy of the GNU Lesser General Public
  26.    License along with this library; if not, write to the Free Software
  27.    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28.    MA  02111-1307  USA
  29.  
  30.  
  31.    Sun Industry Standards Source License Version 1.1
  32.    =================================================
  33.    The contents of this file are subject to the Sun Industry Standards
  34.    Source License Version 1.1 (the "License"); You may not use this file
  35.    except in compliance with the License. You may obtain a copy of the
  36.    License at http://www.openoffice.org/license.html.
  37.  
  38.    Software provided under this License is provided on an "AS IS" basis,
  39.    WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
  40.    WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
  41.    MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
  42.    See the License for the specific provisions governing your rights and
  43.    obligations concerning the Software.
  44.  
  45.    The Initial Developer of the Original Code is: Sun Microsystems, Inc.
  46.  
  47.    Copyright ┬⌐ 2002 by Sun Microsystems, Inc.
  48.  
  49.    All Rights Reserved.
  50.  
  51.    Contributor(s): _______________________________________
  52.    
  53.  -->
  54. <!--
  55.      xslt math lib by Wind Li
  56. Public Functions 
  57.     sin(x,rounding-factor=100)
  58.     cos(x,rounding-factor=100)
  59.     tan(x,rounding-factor=100)
  60.     ctan(x,rounding-factor=100)
  61.     atan2(x, y ,rounding-factor=100)
  62.     atan(x,rounding-factor=100)
  63.     acos(x,rounding-factor=100)
  64.     asin(x,rounding-factor=100)
  65.     abs(x)
  66.     max(x1,x2)
  67.     min(x1,x2)
  68.     power(x,power(interger only), rounding-factor=100)
  69.     sqrt(x, rounding-factor=100)
  70.     convert2radian(x,rounding-factor=100)
  71.     convert2degree(x,rounding-factor=100)
  72.     convert2fd(x,rounding-factor=100)
  73.  -->
  74. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:svg="http://www.w3.org/2000/svg" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:text="http://openoffice.org/2000/text" xmlns:style="http://openoffice.org/2000/style" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:office="http://openoffice.org/2000/office" exclude-result-prefixes="draw svg style office fo text">
  75.     <xsl:variable name="pi" select="3.1416"/>
  76.     <xsl:template name="math-test">
  77.         sin(34.8)
  78.         <xsl:call-template name="sin">
  79.             <xsl:with-param name="x" select="34.8"/>
  80.             <xsl:with-param name="rounding-factor" select="100000"/>
  81.         </xsl:call-template>
  82.         cos(34.8)
  83.         <xsl:call-template name="cos">
  84.             <xsl:with-param name="x" select="34.8"/>
  85.             <xsl:with-param name="rounding-factor" select="100000"/>
  86.         </xsl:call-template>
  87.         atan(2.74) 
  88.         <xsl:call-template name="atan">
  89.             <xsl:with-param name="x" select="2.74"/>
  90.             <xsl:with-param name="rounding-factor" select="100000"/>
  91.         </xsl:call-template>
  92.         acos(0.5) 
  93.         <xsl:call-template name="acos">
  94.             <xsl:with-param name="x" select="0.5"/>
  95.             <xsl:with-param name="rounding-factor" select="100000"/>
  96.         </xsl:call-template>
  97.         asin(0.5) 
  98.         <xsl:call-template name="asin">
  99.             <xsl:with-param name="x" select="0.5"/>
  100.             <xsl:with-param name="rounding-factor" select="100000"/>
  101.         </xsl:call-template>
  102.         sqrt(1328.3414)
  103.         <xsl:call-template name="sqrt">
  104.             <xsl:with-param name="x" select="1328.3414"/>
  105.             <xsl:with-param name="rounding-factor" select="100000"/>
  106.         </xsl:call-template>
  107.     </xsl:template>
  108.     <!-- public functions start -->
  109.     <xsl:template name="sin">
  110.         <xsl:param name="x" select="0"/>
  111.         <xsl:param name="rounding-factor" select="100"/>
  112.         <xsl:variable name="angle" select="$x * 180 div $pi "/>
  113.         <xsl:variable name="mod-angle" select="$angle mod 360"/>
  114.         <xsl:variable name="sinx">
  115.             <xsl:call-template name="sin-private">
  116.                 <xsl:with-param name="x" select="  ( $angle mod 360 )  * $pi div 180 "/>
  117.             </xsl:call-template>
  118.         </xsl:variable>
  119.         <xsl:value-of select=" round ( number($sinx) * $rounding-factor ) div $rounding-factor"/>
  120.     </xsl:template>
  121.     <xsl:template name="cos">
  122.         <xsl:param name="x" select="0"/>
  123.         <xsl:param name="rounding-factor" select="100"/>
  124.         <xsl:variable name="angle" select="$x * 180 div $pi "/>
  125.         <xsl:variable name="mod-angle" select="$angle mod 360"/>
  126.         <xsl:variable name="cosx">
  127.             <xsl:call-template name="cos-private">
  128.                 <xsl:with-param name="x" select="  ( $angle mod 360 )  * $pi div 180 "/>
  129.             </xsl:call-template>
  130.         </xsl:variable>
  131.         <xsl:value-of select=" round ( number($cosx) * $rounding-factor ) div $rounding-factor"/>
  132.     </xsl:template>
  133.     <xsl:template name="tan">
  134.         <xsl:param name="x" select="0"/>
  135.         <xsl:param name="rounding-factor" select="100"/>
  136.         <xsl:variable name="sinx">
  137.             <xsl:call-template name="sin">
  138.                 <xsl:with-param name="x" select="$x"/>
  139.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  140.             </xsl:call-template>
  141.         </xsl:variable>
  142.         <xsl:variable name="cosx">
  143.             <xsl:call-template name="cos">
  144.                 <xsl:with-param name="x" select="$x"/>
  145.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  146.             </xsl:call-template>
  147.         </xsl:variable>
  148.         <xsl:choose>
  149.             <xsl:when test=" $cosx = 0 ">
  150.                 <xsl:message>tan error : tan(<xsl:value-of select="$x"/>) is infinite!</xsl:message>
  151.                 <xsl:value-of select="63535"/>
  152.             </xsl:when>
  153.             <xsl:otherwise>
  154.                 <xsl:value-of select=" round( $sinx div $cosx * $rounding-factor) div $rounding-factor"/>
  155.             </xsl:otherwise>
  156.         </xsl:choose>
  157.     </xsl:template>
  158.     <xsl:template name="ctan">
  159.         <xsl:param name="x" select="0"/>
  160.         <xsl:param name="rounding-factor" select="100"/>
  161.         <xsl:variable name="sinx">
  162.             <xsl:call-template name="sin">
  163.                 <xsl:with-param name="x" select="$x"/>
  164.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  165.             </xsl:call-template>
  166.         </xsl:variable>
  167.         <xsl:variable name="cosx">
  168.             <xsl:call-template name="cos">
  169.                 <xsl:with-param name="x" select="$x"/>
  170.                 <xsl:with-param name="rounding-factor" select="$rounding-factor * 10"/>
  171.             </xsl:call-template>
  172.         </xsl:variable>
  173.         <xsl:choose>
  174.             <xsl:when test=" $sinx = 0 ">
  175.                 <xsl:message>tan error : tan(<xsl:value-of select="$x"/>) is infinite!</xsl:message>
  176.                 <xsl:value-of select="63535"/>
  177.             </xsl:when>
  178.             <xsl:otherwise>
  179.                 <xsl:value-of select=" round( $cosx div $sinx * $rounding-factor) div $rounding-factor"/>
  180.             </xsl:otherwise>
  181.         </xsl:choose>
  182.     </xsl:template>
  183.     <xsl:template name="atan">
  184.         <xsl:param name="x" select="0"/>
  185.         <xsl:param name="rounding-factor" select="100"/>
  186.         <xsl:choose>
  187.             <xsl:when test="$x = 0">
  188.                 <xsl:value-of select="0"/>
  189.             </xsl:when>
  190.             <xsl:when test="$x < 0">
  191.                 <xsl:variable name="atan-x">
  192.                     <xsl:call-template name="atan">
  193.                         <xsl:with-param name="x" select=" -1 * $x"/>
  194.                         <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  195.                     </xsl:call-template>
  196.                 </xsl:variable>
  197.                 <xsl:value-of select="-1 * $atan-x"/>
  198.             </xsl:when>
  199.             <xsl:when test="$x > 1">
  200.                 <xsl:variable name="atan-div-x">
  201.                     <xsl:call-template name="atan">
  202.                         <xsl:with-param name="x" select="1 div $x "/>
  203.                         <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  204.                     </xsl:call-template>
  205.                 </xsl:variable>
  206.                 <xsl:value-of select=" $pi div 2 - $atan-div-x"/>
  207.             </xsl:when>
  208.             <xsl:otherwise>
  209.                 <xsl:variable name="arctanx">
  210.                     <xsl:call-template name="atan-private">
  211.                         <xsl:with-param name="x" select="  $x "/>
  212.                     </xsl:call-template>
  213.                 </xsl:variable>
  214.                 <xsl:value-of select=" round ( number($arctanx) * $rounding-factor ) div $rounding-factor"/>
  215.             </xsl:otherwise>
  216.         </xsl:choose>
  217.     </xsl:template>
  218.     <xsl:template name="atan2">
  219.         <xsl:param name="x"/>
  220.         <xsl:param name="y"/>
  221.         <xsl:param name="rounding-factor" select="100"/>
  222.         <xsl:choose>
  223.             <xsl:when test="$x = 0">
  224.                 <xsl:value-of select=" $pi div 2"/>
  225.             </xsl:when>
  226.             <xsl:otherwise>
  227.                 <xsl:call-template name="atan">
  228.                     <xsl:with-param name="x" select="$y div $x"/>
  229.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  230.                 </xsl:call-template>
  231.             </xsl:otherwise>
  232.         </xsl:choose>
  233.     </xsl:template>
  234.     <xsl:template name="acos">
  235.         <xsl:param name="x"/>
  236.         <xsl:param name="rounding-factor" select="100"/>
  237.         <xsl:variable name="abs-x">
  238.             <xsl:call-template name="abs">
  239.                 <xsl:with-param name="x" select="$x"/>
  240.             </xsl:call-template>
  241.         </xsl:variable>
  242.         <xsl:choose>
  243.             <xsl:when test="$abs-x  >  1">
  244.                 <xsl:message>acos error : abs(<xsl:value-of select="$x"/>) greate then 1 !</xsl:message>
  245.             </xsl:when>
  246.             <xsl:otherwise>
  247.                 <xsl:call-template name="atan2">
  248.                     <xsl:with-param name="x" select="$x"/>
  249.                     <xsl:with-param name="y">
  250.                         <xsl:call-template name="sqrt">
  251.                             <xsl:with-param name="x" select="1 - $x * $x"/>
  252.                             <xsl:with-param name="rounding-factor" select=" concat($rounding-factor,'0') "/>
  253.                         </xsl:call-template>
  254.                     </xsl:with-param>
  255.                 </xsl:call-template>
  256.             </xsl:otherwise>
  257.         </xsl:choose>
  258.     </xsl:template>
  259.     <xsl:template name="asin">
  260.         <xsl:param name="x"/>
  261.         <xsl:param name="rounding-factor" select="100"/>
  262.         <xsl:variable name="abs-x">
  263.             <xsl:call-template name="abs">
  264.                 <xsl:with-param name="x" select="$x"/>
  265.             </xsl:call-template>
  266.         </xsl:variable>
  267.         <xsl:choose>
  268.             <xsl:when test="$abs-x  >  1">
  269.                 <xsl:message>asin error : abs(<xsl:value-of select="$x"/>) greate then 1 !</xsl:message>
  270.             </xsl:when>
  271.             <xsl:otherwise>
  272.                 <xsl:call-template name="atan2">
  273.                     <xsl:with-param name="y" select="$x"/>
  274.                     <xsl:with-param name="x">
  275.                         <xsl:call-template name="sqrt">
  276.                             <xsl:with-param name="x" select="1 - $x * $x"/>
  277.                             <xsl:with-param name="rounding-factor" select=" concat($rounding-factor,'0') "/>
  278.                         </xsl:call-template>
  279.                     </xsl:with-param>
  280.                 </xsl:call-template>
  281.             </xsl:otherwise>
  282.         </xsl:choose>
  283.     </xsl:template>
  284.     <xsl:template name="abs">
  285.         <xsl:param name="x"/>
  286.         <xsl:choose>
  287.             <xsl:when test="$x > 0">
  288.                 <xsl:value-of select="$x"/>
  289.             </xsl:when>
  290.             <xsl:otherwise>
  291.                 <xsl:value-of select="$x * -1"/>
  292.             </xsl:otherwise>
  293.         </xsl:choose>
  294.     </xsl:template>
  295.     <xsl:template name="max">
  296.         <xsl:param name="x1"/>
  297.         <xsl:param name="x2"/>
  298.         <xsl:choose>
  299.             <xsl:when test="$x1 >  $x2">
  300.                 <xsl:value-of select="$x1"/>
  301.             </xsl:when>
  302.             <xsl:otherwise>
  303.                 <xsl:value-of select="$x2"/>
  304.             </xsl:otherwise>
  305.         </xsl:choose>
  306.     </xsl:template>
  307.     <xsl:template name="min">
  308.         <xsl:param name="x1"/>
  309.         <xsl:param name="x2"/>
  310.         <xsl:choose>
  311.             <xsl:when test="$x1 <  $x2">
  312.                 <xsl:value-of select="$x1"/>
  313.             </xsl:when>
  314.             <xsl:otherwise>
  315.                 <xsl:value-of select="$x2"/>
  316.             </xsl:otherwise>
  317.         </xsl:choose>
  318.     </xsl:template>
  319.     <xsl:template name="power">
  320.         <xsl:param name="x"/>
  321.         <xsl:param name="y" select="1"/>
  322.         <xsl:param name="rounding-factor" select="100"/>
  323.         <!--  z is a private param -->
  324.         <xsl:param name="z" select="1"/>
  325.         <xsl:choose>
  326.             <xsl:when test="$y > 0">
  327.                 <xsl:call-template name="power">
  328.                     <xsl:with-param name="x" select="$x"/>
  329.                     <xsl:with-param name="y" select="$y - 1"/>
  330.                     <xsl:with-param name="z" select="$z * $x"/>
  331.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  332.                 </xsl:call-template>
  333.             </xsl:when>
  334.             <xsl:otherwise>
  335.                 <xsl:value-of select=" round( $z * $rounding-factor) div $rounding-factor"/>
  336.             </xsl:otherwise>
  337.         </xsl:choose>
  338.     </xsl:template>
  339.     <xsl:template name="sqrt">
  340.         <xsl:param name="x"/>
  341.         <xsl:param name="rounding-factor" select="100"/>
  342.         <xsl:choose>
  343.             <xsl:when test="$x = 0">0</xsl:when>
  344.             <xsl:when test="$x < 0">
  345.                 <xsl:message>sqrt error : <xsl:value-of select="$x"/>  less then 0!</xsl:message>
  346.             </xsl:when>
  347.             <xsl:otherwise>
  348.                 <xsl:call-template name="sqrt-private">
  349.                     <xsl:with-param name="x" select="$x"/>
  350.                     <xsl:with-param name="rounding-factor" select="$rounding-factor"/>
  351.                 </xsl:call-template>
  352.             </xsl:otherwise>
  353.         </xsl:choose>
  354.     </xsl:template>
  355.     <!-- public functions end -->
  356.     <!-- 
  357. Private functions:
  358. sin-private
  359. cos-private
  360. atan-private
  361. sqrt-private
  362. integer-sqrt
  363. Sqrt-GetOneDigit
  364. -->
  365.     <xsl:template name="sin-private">
  366.         <xsl:param name="x" select="0"/>
  367.         <xsl:param name="n" select="0"/>
  368.         <xsl:param name="nx" select="1"/>
  369.         <xsl:param name="sign" select="1"/>
  370.         <xsl:param name="max-n" select="20"/>
  371.         <xsl:param name="sinx" select="0"/>
  372.         <xsl:choose>
  373.             <xsl:when test="not ($max-n >  $n) or $nx = 0 ">
  374.                 <xsl:value-of select="$sinx"/>
  375.             </xsl:when>
  376.             <xsl:when test="$n = 0">
  377.                 <xsl:call-template name="sin-private">
  378.                     <xsl:with-param name="x" select="$x"/>
  379.                     <xsl:with-param name="n" select="$n + 1"/>
  380.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  381.                     <xsl:with-param name="max-n" select="$max-n"/>
  382.                     <xsl:with-param name="nx" select="$x "/>
  383.                     <xsl:with-param name="sinx" select="$sinx + $x"/>
  384.                 </xsl:call-template>
  385.             </xsl:when>
  386.             <xsl:otherwise>
  387.                 <xsl:variable name="new-nx" select="($nx * $x * $x)  div ( 2  *  $n )  div ( 2  *  $n  + 1)  "/>
  388.                 <xsl:call-template name="sin-private">
  389.                     <xsl:with-param name="x" select="$x"/>
  390.                     <xsl:with-param name="n" select="$n + 1"/>
  391.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  392.                     <xsl:with-param name="max-n" select="$max-n"/>
  393.                     <xsl:with-param name="nx" select=" $new-nx "/>
  394.                     <xsl:with-param name="sinx" select="$sinx + $new-nx  * $sign"/>
  395.                 </xsl:call-template>
  396.             </xsl:otherwise>
  397.         </xsl:choose>
  398.     </xsl:template>
  399.     <xsl:template name="cos-private">
  400.         <xsl:param name="x" select="0"/>
  401.         <xsl:param name="n" select="0"/>
  402.         <xsl:param name="nx" select="1"/>
  403.         <xsl:param name="sign" select="1"/>
  404.         <xsl:param name="max-n" select="20"/>
  405.         <xsl:param name="cosx" select="0"/>
  406.         <xsl:choose>
  407.             <xsl:when test="not ($max-n >  $n)  or $nx = 0  ">
  408.                 <xsl:value-of select="$cosx"/>
  409.             </xsl:when>
  410.             <xsl:when test="$n = 0">
  411.                 <xsl:call-template name="cos-private">
  412.                     <xsl:with-param name="x" select="$x"/>
  413.                     <xsl:with-param name="n" select="$n + 1"/>
  414.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  415.                     <xsl:with-param name="max-n" select="$max-n"/>
  416.                     <xsl:with-param name="nx" select=" 1 "/>
  417.                     <xsl:with-param name="cosx" select="1"/>
  418.                 </xsl:call-template>
  419.             </xsl:when>
  420.             <xsl:otherwise>
  421.                 <xsl:variable name="new-nx" select="($nx * $x * $x)  div ( 2  *  $n  -1 )  div ( 2  *  $n )  "/>
  422.                 <xsl:call-template name="cos-private">
  423.                     <xsl:with-param name="x" select="$x"/>
  424.                     <xsl:with-param name="n" select="$n + 1"/>
  425.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  426.                     <xsl:with-param name="max-n" select="$max-n"/>
  427.                     <xsl:with-param name="nx" select=" $new-nx "/>
  428.                     <xsl:with-param name="cosx" select="$cosx + $new-nx  * $sign"/>
  429.                 </xsl:call-template>
  430.             </xsl:otherwise>
  431.         </xsl:choose>
  432.     </xsl:template>
  433.     <xsl:template name="atan-private">
  434.         <xsl:param name="x" select="0"/>
  435.         <xsl:param name="n" select="0"/>
  436.         <xsl:param name="nx" select="1"/>
  437.         <xsl:param name="sign" select="1"/>
  438.         <xsl:param name="max-n" select="40"/>
  439.         <xsl:param name="arctanx" select="0"/>
  440.         <xsl:choose>
  441.             <xsl:when test="not ($max-n >  $n) or $nx = 0 ">
  442.                 <xsl:value-of select="$arctanx"/>
  443.             </xsl:when>
  444.             <xsl:when test="$n = 0">
  445.                 <xsl:call-template name="atan-private">
  446.                     <xsl:with-param name="x" select="$x"/>
  447.                     <xsl:with-param name="n" select="$n + 1"/>
  448.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  449.                     <xsl:with-param name="max-n" select="$max-n"/>
  450.                     <xsl:with-param name="nx" select="$x "/>
  451.                     <xsl:with-param name="arctanx" select="$arctanx + $x"/>
  452.                 </xsl:call-template>
  453.             </xsl:when>
  454.             <xsl:otherwise>
  455.                 <xsl:variable name="new-nx" select=" $nx * $x * $x "/>
  456.                 <xsl:call-template name="atan-private">
  457.                     <xsl:with-param name="x" select="$x"/>
  458.                     <xsl:with-param name="n" select="$n + 1"/>
  459.                     <xsl:with-param name="sign" select="$sign *  -1"/>
  460.                     <xsl:with-param name="max-n" select="$max-n"/>
  461.                     <xsl:with-param name="nx" select=" $new-nx "/>
  462.                     <xsl:with-param name="arctanx" select="$arctanx + $new-nx div (2 * $n +1)  * $sign"/>
  463.                 </xsl:call-template>
  464.             </xsl:otherwise>
  465.         </xsl:choose>
  466.     </xsl:template>
  467.     <xsl:template name="sqrt-private">
  468.         <xsl:param name="x"/>
  469.         <xsl:param name="rounding-factor" select="100"/>
  470.         <xsl:variable name="shift" select="string-length( $rounding-factor)"/>
  471.         <xsl:variable name="power">
  472.             <xsl:call-template name="power">
  473.                 <xsl:with-param name="x" select="100"/>
  474.                 <xsl:with-param name="y" select="$shift"/>
  475.                 <xsl:with-param name="rounding-factor" select="1"/>
  476.             </xsl:call-template>
  477.         </xsl:variable>
  478.         <xsl:variable name="integer-x" select=" round( $power * $x )"/>
  479.         <xsl:variable name="integer-quotient">
  480.             <xsl:call-template name="integer-sqrt">
  481.                 <xsl:with-param name="x" select="$integer-x"/>
  482.                 <xsl:with-param name="length" select=" string-length( $integer-x ) "/>
  483.                 <xsl:with-param name="curr-pos" select=" 2 -  (round (string-length( $integer-x ) div 2 )  * 2 - string-length( $integer-x ) ) "/>
  484.             </xsl:call-template>
  485.         </xsl:variable>
  486.         <xsl:variable name="power-10">
  487.             <xsl:call-template name="power">
  488.                 <xsl:with-param name="x" select="10"/>
  489.                 <xsl:with-param name="y" select="$shift - 1"/>
  490.                 <xsl:with-param name="rounding-factor" select="1"/>
  491.             </xsl:call-template>
  492.         </xsl:variable>
  493.         <xsl:value-of select="  round( $integer-quotient div 10) div $power-10 "/>
  494.     </xsl:template>
  495.     <xsl:template name="integer-sqrt">
  496.         <xsl:param name="x"/>
  497.         <xsl:param name="length"/>
  498.         <xsl:param name="curr-pos"/>
  499.         <xsl:param name="last-quotient" select="0"/>
  500.         <xsl:choose>
  501.             <xsl:when test="$curr-pos > $length">
  502.                 <xsl:value-of select="$last-quotient"/>
  503.             </xsl:when>
  504.             <xsl:otherwise>
  505.                 <xsl:variable name="curr-x" select="substring( $x, 1,  $curr-pos )"/>
  506.                 <xsl:variable name="new-quotient">
  507.                     <xsl:call-template name="get-one-sqrt-digit">
  508.                         <xsl:with-param name="x" select="$curr-x"/>
  509.                         <xsl:with-param name="last-quotient" select="$last-quotient"/>
  510.                         <xsl:with-param name="n" select="5"/>
  511.                         <xsl:with-param name="direct" select="0"/>
  512.                     </xsl:call-template>
  513.                 </xsl:variable>
  514.                 <xsl:call-template name="integer-sqrt">
  515.                     <xsl:with-param name="x" select="$x"/>
  516.                     <xsl:with-param name="length" select="$length"/>
  517.                     <xsl:with-param name="curr-pos" select="$curr-pos + 2"/>
  518.                     <xsl:with-param name="last-quotient" select="number($new-quotient)"/>
  519.                 </xsl:call-template>
  520.             </xsl:otherwise>
  521.         </xsl:choose>
  522.     </xsl:template>
  523.     <xsl:template name="get-one-sqrt-digit">
  524.         <xsl:param name="x"/>
  525.         <xsl:param name="last-quotient"/>
  526.         <xsl:param name="n"/>
  527.         <xsl:param name="direct" select="1"/>
  528.         <xsl:variable name="quotient" select=" concat( $last-quotient, $n) "/>
  529.         <xsl:variable name="accumulate" select="$quotient * $quotient "/>
  530.         <xsl:choose>
  531.             <xsl:when test="$accumulate  =  $x">
  532.                 <xsl:value-of select="concat($last-quotient , $n  )"/>
  533.             </xsl:when>
  534.             <xsl:when test="$direct = 0 and $accumulate  <  $x">
  535.                 <xsl:call-template name="get-one-sqrt-digit">
  536.                     <xsl:with-param name="x" select="$x"/>
  537.                     <xsl:with-param name="last-quotient" select="$last-quotient"/>
  538.                     <xsl:with-param name="n" select="$n + 1"/>
  539.                     <xsl:with-param name="direct" select="1"/>
  540.                 </xsl:call-template>
  541.             </xsl:when>
  542.             <xsl:when test="$direct = 0 and $accumulate  >  $x">
  543.                 <xsl:call-template name="get-one-sqrt-digit">
  544.                     <xsl:with-param name="x" select="$x"/>
  545.                     <xsl:with-param name="last-quotient" select="$last-quotient"/>
  546.                     <xsl:with-param name="n" select="$n - 1"/>
  547.                     <xsl:with-param name="direct" select="-1"/>
  548.                 </xsl:call-template>
  549.             </xsl:when>
  550.             <xsl:when test=" $accumulate * $direct  <  $x * $direct  ">
  551.                 <xsl:call-template name="get-one-sqrt-digit">
  552.                     <xsl:with-param name="x" select="$x"/>
  553.                     <xsl:with-param name="last-quotient" select="$last-quotient"/>
  554.                     <xsl:with-param name="n" select="$n+ $direct"/>
  555.                     <xsl:with-param name="direct" select="$direct"/>
  556.                 </xsl:call-template>
  557.             </xsl:when>
  558.             <xsl:when test="not($n < 9)  or $n = -1">
  559.                 <xsl:value-of select="concat($last-quotient , $n - $direct) "/>
  560.             </xsl:when>
  561.             <xsl:when test="$direct = 1">
  562.                 <xsl:value-of select="concat($last-quotient , $n - 1) "/>
  563.             </xsl:when>
  564.             <xsl:otherwise>
  565.                 <xsl:value-of select="concat($last-quotient , $n) "/>
  566.             </xsl:otherwise>
  567.         </xsl:choose>
  568.     </xsl:template>
  569.     <xsl:template name="convert2redian">
  570.         <xsl:param name="x" select="'0'"/>
  571.         <xsl:param name="rounding-factor" select="100"/>
  572.         <xsl:choose>
  573.             <xsl:when test="contains($x,'deg')">
  574.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'deg') div 180 * $pi)) div $rounding-factor"/>
  575.             </xsl:when>
  576.             <xsl:when test="contains($x,'fd')">
  577.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd') div 180 div 65536 * $pi)) div $rounding-factor"/>
  578.             </xsl:when>
  579.             <xsl:otherwise>
  580.                 <xsl:value-of select="round($rounding-factor * number($x) div 180 * $pi) div $rounding-factor"/>
  581.             </xsl:otherwise>
  582.         </xsl:choose> 
  583.     </xsl:template>
  584.     <xsl:template name="convert2degree">
  585.         <xsl:param name="x" select="'0'"/>
  586.         <xsl:param name="rounding-factor" select="100"/>
  587.         <xsl:choose>
  588.             <xsl:when test="contains($x,'deg')">
  589.                 <xsl:value-of select="round($rounding-factor * substring-before($x,'deg')) div $rounding-factor"/>
  590.             </xsl:when>
  591.             <xsl:when test="contains($x,'fd')">
  592.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd')) div 65536 ) div $rounding-factor"/>
  593.             </xsl:when>
  594.             <xsl:otherwise>
  595.                 <xsl:value-of select="round($rounding-factor * number($x) * 180 div $pi) div $rounding-factor"/>
  596.             </xsl:otherwise>
  597.         </xsl:choose> 
  598.     </xsl:template>
  599.     <xsl:template name="convert2fd">
  600.         <xsl:param name="x" select="'0'"/>
  601.         <xsl:param name="rounding-factor" select="100"/>
  602.         <xsl:choose>
  603.             <xsl:when test="contains($x,'deg')">
  604.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'deg') * 65535)) div $rounding-factor"/>
  605.             </xsl:when>
  606.             <xsl:when test="contains($x,'fd')">
  607.                 <xsl:value-of select="round($rounding-factor * number(substring-before($x, 'fd'))) div $rounding-factor"/>
  608.             </xsl:when>
  609.             <xsl:otherwise>
  610.                 <xsl:value-of select="round($rounding-factor * number($x) * 180 div $pi * 65535) div $rounding-factor"/>
  611.             </xsl:otherwise>
  612.         </xsl:choose> 
  613.     </xsl:template>
  614.  
  615. </xsl:stylesheet>
  616.